
-- -- -- -- -- -- -- --
-- -- Projectile -- -- -- --
-- -- -- -- -- -- -- --


Projectile = Gameelement:new{
  cost = 0, --TODO destinction between spells and arrows
  damage = 0,
  speed = 1,
  wid = 10,
  hig = 10
}




Projectile.image = {
	default = 'resources/default.png'
}

Projectile.states = { flying = {
starting = {
	
},

running = {function (t)
	if t.x + t.wid < 0 or t.y < 0 or t.y +  t.hig > SCREEN_HEIGHT or t.x > SCREEN_WIDTH then 	t:destroy()	end end,
-- TODO: collid function! make it global! like function collide(something, anythin)
function (t)
		if #enemies > 0 then
			for i = 1, #enemies do
				if 	t.x + t.wid > enemies[i].x and 
					t.x < enemies[i].x + enemies[i].wid and 
					t.y + t.hig > enemies[i].y  and 
					t.y < enemies[i].y + enemies[i].hig
				then 	enemies[i]:damage(t.damage) -- TODO: damage ? dmg?
						t:destroy()
					  table.remove(enemies, i)
						break
				end
			end		
		end
end
},
ending = {},
process = 'running'
},
-- when target meets arrow
intarget = {
name = 'intarget'
}
}
Projectile.currentstate = Projectile.states.flying
Projectile.currentstate.process = 'running'
------------------------------------------------

Arrow = Projectile:new{
  cost = 1,
  damage = 13,
  speed = 2,
  wid = 2,
  hig = 2
}
Arrow.image = {
default = 'resources/onearrow.png'
}
Arrow.states = { flying = {
starting = {},
running = {function (t)
	if t.x + t.wid < 0 or t.y < 0 or t.y +  t.hig > SCREEN_HEIGHT or t.x > SCREEN_WIDTH then 	t:destroy()	end end,
--TODO: collid function! make it global! like function collide(something, anythin)
		function (t)
				if #enemies > 0 then
					for i = 1, #enemies do
						if 	t.x + t.wid > enemies[i].x and 
							t.x < enemies[i].x + enemies[i].wid and 
							t.y + t.hig > enemies[i].y  and 
							t.y < enemies[i].y + enemies[i].hig
						then 	enemies[i]:damage(t.damage) -- TODO: damage ? dmg?
								t:destroy()
							  table.remove(enemies, i)
								break
						end
					end		
				end
		end
},
ending = {},
process = 'running'
},
-- when target meets arrow
intarget = {
name = 'intarget'
}
}
Arrow.currentstate = Arrow.states.flying
Arrow.currentstate.process = 'running'

-- -- -- -- -- -- -- --
-- -- Fireball -- -- --
-- -- -- -- -- -- -- --
Fireball = Projectile:new{ -- TODO: Skill? --Skill:new{
speed = 1.5,
cost = 10,
damage = 15,
wid = 20,
hig = 20,
image = {
	default = "resources/onefireball.png"	
}
}

-- -- -- -- -- -- -- --
-- -- Lightning -- -- --
-- -- -- -- -- -- -- --
Lightning = Projectile:new{ -- TODO: Skill? --Skill:new{
speed = 1.5,
cost = 10,
damage = 15,
wid = 20,
hig = 20,
image = {
	default = "resources/lightning.png"	
}
}
